package com.iniyo.ai.poetry.api;

import com.baidu.aip.client.BaseClient;
import com.baidu.aip.http.AipRequest;
import com.baidu.aip.http.EBodyFormat;
import org.json.JSONObject;

public class AipCreation extends BaseClient {
    public AipCreation(String appId, String apiKey, String secretKey) {
        super(appId, apiKey, secretKey);
    }

    /**
     * 智能写诗
     * 根据用户输入的命题关键词自动生成一首7言绝句。
     * @param text 	字符串（限5字符数以内）即作诗的主题
     * @param index 整数 默认为数值为0，即第一首诗。每换一次，数值加1即可，一定数量后会返回之前的作诗结果
     * @return
     */
    public JSONObject poem(String text, Integer index) {
        AipRequest request = new AipRequest();
        this.preOperation(request);
        request.addBody("text", text);
        request.addBody("index", index);

        request.setUri("https://aip.baidubce.com/rpc/2.0/creation/v1/poem");
        request.addHeader("Content-Encoding", "utf-8");
        request.addHeader("Content-Type", "application/json");
        request.setBodyFormat(EBodyFormat.RAW_JSON);
        this.postOperation(request);
        return this.requestServer(request);
    }

    /**
     * 智能春联
     * 根据用户输入的命题关键词自动生成一首7言绝句。
     * @param text 	字符串（限5字符数以内）即作诗的主题
     * @param index 整数 默认为数值为0，即第一首诗。每换一次，数值加1即可，一定数量后会返回之前的作诗结果
     * @return
     */
    public JSONObject couplets(String text, Integer index) {
        AipRequest request = new AipRequest();
        this.preOperation(request);
        request.addBody("text", text);
        request.addBody("index", index);

        request.setUri("https://aip.baidubce.com/rpc/2.0/creation/v1/couplets");
        request.addHeader("Content-Encoding", "utf-8");
        request.addHeader("Content-Type", "application/json");
        request.setBodyFormat(EBodyFormat.RAW_JSON);
        this.postOperation(request);
        return this.requestServer(request);
    }
}
